﻿using Model;
using System.Data.Entity;
using System.Linq;

namespace Business
{
    public class AttachmentBiz
    {
        public int SaveItem(Attachment item)
        {
            var dbContext = new Context();

            dbContext.Attachments.Add(item);
            dbContext.SaveChanges();

            return item.Id;
        }

        public void UpdateItem(Attachment item)
        {
            var dbContext = new Context();
            dbContext.Entry(item).State = EntityState.Modified;
            dbContext.SaveChanges();
        }

        public Attachment LoadItem(int id)
        {
            var dbContext = new Context();
            return (from item in dbContext.Attachments
                    where item.Id == id
                    select item).First();
        }
    }
}
